using System;
using UnityEngine;

[Serializable]
public class animation_curve_class
{
	public bool curve_in_memory;

	public string curve_text;

	public Rect menu_rect;

	public AnimationCurve curve;

	public AnimationCurve default_curve;

	public bool abs;

	public curve_type_enum type;

	public bool active;

	public bool settings_foldout;

	public float frequency;

	public Vector2 offset;

	public Vector2 offset_range;

	public Vector2 offset_middle;

	public int detail;

	public float detail_strength;

	public Transform pivot;

	public float strength;

	public bool rotation;

	public float rotation_value;

	public animation_curve_class()
	{
		curve_text = "Curve";
		curve = new AnimationCurve();
		default_curve = new AnimationCurve();
		active = true;
		settings_foldout = true;
		frequency = 256f;
		offset_range = new Vector2(5f, 5f);
		detail = 1;
		detail_strength = 2f;
		strength = 1f;
	}

	public void set_zero()
	{
		curve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
	}

	public void set_invert()
	{
		AnimationCurve animationCurve = new AnimationCurve();
		for (int i = 0; i < curve.keys.Length; i++)
		{
			Keyframe key = curve.keys[i];
			key.value = 1f - key.value;
			float inTangent = key.inTangent;
			key.inTangent *= -1f;
			key.outTangent *= -1f;
			animationCurve.AddKey(key);
		}
		curve = new AnimationCurve(animationCurve.keys);
	}

	public void set_default()
	{
		curve = new AnimationCurve(default_curve.keys);
	}

	public void set_as_default()
	{
		default_curve = new AnimationCurve(curve.keys);
	}

	public void default_normal()
	{
		curve = AnimationCurve.Linear(0f, 0f, 1f, 1f);
		type = curve_type_enum.Normal;
	}

	public void default_random()
	{
		curve = AnimationCurve.Linear(0f, 0f, 1f, 0f);
		type = curve_type_enum.Random;
	}

	public void default_perlin()
	{
		curve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
		type = curve_type_enum.Perlin;
		frequency = 256f;
		offset = new Vector2(0f, 0f);
		offset_middle = new Vector2(0f, 0f);
		detail = 7;
		detail_strength = 2f;
		abs = false;
	}

	public void change_key(float time, float value)
	{
		if (curve.AddKey(time, value) != -1)
		{
			return;
		}
		Keyframe[] keys = curve.keys;
		for (int i = 0; i < curve.keys.Length; i++)
		{
			if (keys[i].time == time)
			{
				keys[i].value = value;
			}
		}
		curve = new AnimationCurve(keys);
	}

	public void set_curve_linear()
	{
		AnimationCurve animationCurve = new AnimationCurve();
		for (int i = 0; i < curve.keys.Length; i++)
		{
			float inTangent = 0f;
			float outTangent = 0f;
			bool flag = false;
			bool flag2 = false;
			Vector2 b = default(Vector2);
			Vector2 a = default(Vector2);
			Vector2 vector = default(Vector2);
			Keyframe key = curve[i];
			if (i == 0)
			{
				inTangent = 0f;
				flag = true;
			}
			if (i == curve.keys.Length - 1)
			{
				outTangent = 0f;
				flag2 = true;
			}
			if (!flag)
			{
				b.x = curve.keys[i - 1].time;
				b.y = curve.keys[i - 1].value;
				a.x = curve.keys[i].time;
				a.y = curve.keys[i].value;
				vector = a - b;
				inTangent = vector.y / vector.x;
			}
			if (!flag2)
			{
				b.x = curve.keys[i].time;
				b.y = curve.keys[i].value;
				a.x = curve.keys[i + 1].time;
				a.y = curve.keys[i + 1].value;
				vector = a - b;
				outTangent = vector.y / vector.x;
			}
			key.inTangent = inTangent;
			key.outTangent = outTangent;
			animationCurve.AddKey(key);
		}
		curve = animationCurve;
	}
}
